// futures funding rates
use "build/output/futures_funding_long.dta", clear
append using "build/input/ftx/ftx_futures_pseudo.dta"


keep if inlist(coin, "BTC", "ETH", "DOGE")

gen pair = coin+base+"_"+exchange

keep funding_apr date pair

drop if date < mdy(12,1,2020)
drop if date > mdy(11,5,2022)

reshape wide funding_apr, i(date) j(pair) string

merge m:1 date using "build/output/bbg_crypto_futures.dta", nogen

label var funding_aprBTCUSDT_Binance "BTC/USDT, Binance"
label var funding_aprETHUSDT_Binance "ETH/USDT, Binance"
label var funding_aprBTCBUSD_Binance "BTC/BUSD, Binance"
label var funding_aprDOGEUSDT_Binance "DOGE/BUSD, Binance"
label var funding_aprBTCUSD_FTX "BTC/USD, FTX"
label var funding_aprETHUSD_FTX "ETH/USD, FTX"
label var funding_aprDOGEUSD_FTX "DOGE/USD, FTX"
label var e_rBTC_2m_annualized "\$\mathbb{E}[R^{\textit{BTC}}]\$"
label var e_rETH_2m_annualized "\$\mathbb{E}[R^{\textit{ETH}}]\$"


eststo clear
estpost correlate funding_aprBTCUSDT_Binance funding_aprETHUSDT_Binance funding_aprBTCBUSD_Binance funding_aprDOGEUSDT_Binance funding_aprBTCUSD_FTX funding_aprETHUSD_FTX e_rBTC_2m_annualized e_rETH_2m_annualized, matrix
esttab, unstack compress
esttab using "analysis/output_tables/table_y_robustness.tex", replace booktabs /// 
star(* 0.10 ** 0.05 *** 0.01) ///
label not unstack compress noobs style(tex) substitute(\_ _) b(2) alignment(l) ///
 collabels(none) mlabels(none) nonumber mgroups(none)
 
 
reg funding_aprBTCBUSD_Binance funding_aprBTCUSD_FTX, r
reg funding_aprETHUSDT_Binance funding_aprETHUSD_FTX, r


